package com.zheng.damo01.作业;

import java.util.Scanner;

public class Test03 {
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        System.out.println("请输入源字符串");
        String str1=s.nextLine();
        System.out.println("请输入要删除的字符串");
        String str2=s.nextLine();
        StringBuilder sb=new StringBuilder();

        char[] chars=str1.toCharArray();
        int count=0;
        int stratccount=0;
        while (true){
            int index;
            if (count==0){
                index = str1.indexOf(str2,0);
            }else {
                index = str1.indexOf(str2,stratccount+str2.length());
            }
            if (index!=-1){
                count++;
                for (int i = stratccount; i < index; i++) {
                    sb.append(chars[i]);
                }
                stratccount=index+str2.length();
            }else {
                break;
            }
        }
        System.out.println("元字符包含"+count+"个"+str2);
        System.out.println("删除"+str2+"后的字符为："+sb.toString());



    }
}
